//ES6  方式引入
import axios from "../api/index";
import MockAdapter from "axios-mock-adapter";

//创建默认实例对象
let Mock = new MockAdapter(axios);

//模拟服务器响应
Mock.onPost("/login").reply((config) => {
  //获取请求的参数
  const user = JSON.parse(config.data);
  //模拟账户校验
  if (user.username === "zs" && user.pwd === "123456") {
    return [
      200,
      {
        code: 200,
        msg: "success",
        //模拟token
        token: "12345678910",
      },
    ];
  } else {
    return [
      400,
      {
        code: 1,
        msg: "登陆失败,账号或者密码错误！",
      },
    ];
  }
});

//将get请求放行, 让它去请求服务器
Mock.onGet().passThrough();
